package com.lrkj.back.controller;

import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lrkj.back.StartUpOnLoadData;
import com.lrkj.back.entity.*;
import com.lrkj.back.service.TbEmployeeService;
import com.lrkj.back.service.ZsHuishouMingxiService;
import com.lrkj.back.service.ZsWanglanpackageService;
import com.lrkj.back.Const;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lrkj.back.service.TbSeqService;
import com.lrkj.back.service.ZsEquipService;
import com.lrkj.back.service.ZsHuishouService;
import com.lrkj.back.service.ZsPackageImformationService;
import com.lrkj.back.service.ZsQingxiBuhegeService;
import com.lrkj.back.service.ZsQingxiMingxiService;
import com.lrkj.back.service.ZsQingxiService;
import com.lrkj.back.service.ZsSoftService;
import com.lrkj.back.service.ZsWanglanService;
import cn.com.cbons.mamisay.parent.exception.BusinessException;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/qingxi")
public class ZsQingxiController extends BaseController {

    @Autowired
    private TbEmployeeService tbEmployeeService;

    @Autowired
    private ZsQingxiService zsqingxiService;

    @Autowired
    private ZsHuishouMingxiService zsHuishouMingxi;

    @Autowired
    private ZsEquipService zsEquipservice;

    @Autowired
    private ZsSoftService zsSoftService;

    @Autowired
    private ZsWanglanService zsWanglanService;
    // 查询网篮对应的包
    @Autowired
    private ZsHuishouMingxiService zsHuishouMingxiService;

    @Autowired
    private ZsHuishouService zsHuishouService;

    @Autowired
    private TbSeqService seqService;

    @Autowired
    private ZsQingxiMingxiService zsQingxiMingxiService;

    @Autowired
    private ZsWanglanpackageService zsWlPackService;

    @Autowired
    private ZsPackageImformationService zsPackageImService;

    @Autowired
    private ZsQingxiBuhegeService zsQXBhgService;

    @Autowired
    private ZsEquipService zsEquipService;

    String[] qingxiWanglanTiaoma;

    /**
     * 清单界面查询全部的清洗清单
     *
     * @param searchTxt 关键词搜索
     * @return
     */
    @RequestMapping("/qingxiList.do")
    public ModelAndView qingxiList(String searchTxt, String st, String et) throws BusinessException {
        Integer pageNo = request.getParameter("pageIndex") == null ? 1 : Integer.valueOf(request
                .getParameter("pageIndex"));
        Map<String, Object> map = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startTime = null;
        Date endTime = null;

        if (StringUtils.isNotBlank(searchTxt)) {
            map.put("searchTxt", searchTxt);
        }
        try {
            if (StringUtils.isNotBlank(st)) {
                startTime = sdf.parse(st);
                map.put("startTime", startTime);
            }
            if (StringUtils.isNotBlank(et)) {
                endTime = sdf.parse(et);
                map.put("endTime", endTime);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        map.put("pageNo", pageNo);
        map.put("pageSize", Const.PAGE_SIZE);
        PageInfo<ZsQingxi> page = zsqingxiService.findAllZsQingxi(map);
        request.setAttribute("qingxiList", page.getList());
        request.setAttribute("searchTxt", searchTxt == null ? "" : searchTxt);
        request.setAttribute("total", page.getPages());
        request.setAttribute("empmap", StartUpOnLoadData.emMap);
        request.setAttribute("equipMap", StartUpOnLoadData.equipMap);
        request.setAttribute("softMap", StartUpOnLoadData.softMap);
        request.setAttribute("dictMap", StartUpOnLoadData.singleDataMap);
        return new ModelAndView("/qxxd/qingxi_list");
    }

    @RequestMapping("/qingxiList")
    @ResponseBody
    public Map<String, Object> qingxi(String searchTxt, String st, String et, HttpServletRequest request,
                                      HttpServletResponse response) throws BusinessException {
        Integer pageNo = request.getParameter("pageIndex") == null ? 1 : Integer.valueOf(request
                .getParameter("pageIndex"));
        Map<String, Object> rtnmap = new HashMap<>();
        Map<String, Object> map = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startTime = null;
        Date endTime = null;

        if (StringUtils.isNotBlank(searchTxt)) {
            map.put("searchTxt", searchTxt);
        }
        try {
            if (StringUtils.isNotBlank(st)) {
                startTime = sdf.parse(st);
                map.put("startTime", startTime);
            }
            if (StringUtils.isNotBlank(et)) {
                endTime = sdf.parse(et);
                map.put("endTime", endTime);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        map.put("pageNo", pageNo);
        map.put("pageSize", Const.PAGE_SIZE);
        PageInfo<ZsQingxi> page = zsqingxiService.findAllZsQingxi(map);
        request.setAttribute("qingxiList", page.getList());
        request.setAttribute("searchTxt", searchTxt == null ? "" : searchTxt);
        request.setAttribute("total", page.getPages());
        request.setAttribute("empmap", StartUpOnLoadData.emMap);
        request.setAttribute("equipMap", StartUpOnLoadData.equipMap);
        request.setAttribute("softMap", StartUpOnLoadData.softMap);
        request.setAttribute("dictMap", StartUpOnLoadData.singleDataMap);
        rtnmap.put("data", page);
        return rtnmap;
    }

    /**
     * 清单界面查询全部的清洗清单
     *
     * @param searchTxt 关键词搜索
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/qingxiBuhegeList.do")
    public ModelAndView qingxiBuhegeList(String searchTxt, String st, String et, HttpServletRequest request,
                                         HttpServletResponse response) throws BusinessException {
        Integer pageNo = request.getParameter("pageIndex") == null ? 1 : Integer.valueOf(request
                .getParameter("pageIndex"));
        Map<String, Object> map = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startTime = null;
        Date endTime = null;
        List<ZsQingxiBuhege> zsQingxiBuhegelist = zsQXBhgService.findAllZsQXBHG(map);
        int num = zsQingxiBuhegelist.size();
        String[] zsQingxiBuhegeArr = new String[num];
        int count = 0;
        for (ZsQingxiBuhege zsQingxiBuhege : zsQingxiBuhegelist) {
            zsQingxiBuhegeArr[count] = zsQingxiBuhege.getQingxiLiushui();
            count++;
        }
        if (StringUtils.isNotBlank(searchTxt)) {
            map.put("searchTxt", searchTxt);
        }
        try {
            if (StringUtils.isNotBlank(st)) {
                startTime = sdf.parse(st);
                map.put("startTime", startTime);
            }
            if (StringUtils.isNotBlank(et)) {
                endTime = sdf.parse(et);
                map.put("endTime", endTime);
            }
        } catch (ParseException e) {

            e.printStackTrace();
        }
        if (zsQingxiBuhegeArr.length != 0) {
            map.put("qxlsArr", zsQingxiBuhegeArr);
        } else {
            map.put("no", "1");
        }
        map.put("pageNo", pageNo);
        map.put("pageSize", Const.PAGE_SIZE);
        PageInfo<ZsQingxi> page = zsqingxiService.findAllZsQingxi(map);
        request.setAttribute("qingxiList", page.getList());
        request.setAttribute("searchTxt", searchTxt == null ? "" : searchTxt);
        request.setAttribute("total", page.getPages());
        request.setAttribute("equipMap", StartUpOnLoadData.equipMap);
        request.setAttribute("softMap", StartUpOnLoadData.softMap);
        request.setAttribute("dictMap", StartUpOnLoadData.singleDataMap);
        request.setAttribute("empmap", StartUpOnLoadData.emMap);
        return new ModelAndView("/qxxd/qingxi_buhegelist");
    }

    // 加载清洗名单
    @RequestMapping("/qingxiActionList.do")
    public ModelAndView qingxiWaitList(HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        Integer pageNo = request.getParameter("pageIndex") == null ? 1 : Integer.valueOf(request
                .getParameter("pageIndex"));
        Map<String, Object> map = new HashMap<String, Object>();
        Integer qingxiStatus = 0;
        map.put("qingxiZhuangtai", qingxiStatus);
        map.put("pageNo", pageNo);
        map.put("pageSize", Const.PAGE_SIZE);
        PageInfo<ZsQingxi> page = zsqingxiService.findAllZsQingxi(map);
        request.setAttribute("qingxiList", page.getList());
        request.setAttribute("total", page.getPages());
        request.setAttribute("emMap", StartUpOnLoadData.emMap);
        request.setAttribute("equipMap", StartUpOnLoadData.equipMap);
        request.setAttribute("softMap", StartUpOnLoadData.softMap);
        return new ModelAndView("/qxxd/qingxi_action");
    }

    /**
     * 用于设备添加清洗
     *
     * @param request
     * @param response
     * @return
     * @throws BusinessException
     */
    @RequestMapping("/qingxiEcupidActionList.do")
    public ModelAndView qingxiEcupidActionList(String shebeiTiaoma, String id, HttpServletRequest request,
                                               HttpServletResponse response) throws BusinessException {
        Integer pageNo = request.getParameter("pageIndex") == null ? 1 : Integer.valueOf(request
                .getParameter("pageIndex"));
        Map<String, Object> map = new HashMap<>();
        Integer qingxiStatus = 0;
        map.put("qingxiShebeiTiaoma", shebeiTiaoma);
        map.put("qingxiZhuangtai", qingxiStatus);
        map.put("pageNo", pageNo);
        map.put("pageSize", Const.PAGE_SIZE);
        PageInfo<ZsQingxi> page = zsqingxiService.findAllZsQingxi(map);
        request.setAttribute("qingxiList", page.getList());
        request.setAttribute("total", page.getPages());
        request.setAttribute("id", id);
        return new ModelAndView("/qxxd/qingxi_equipAdd");
    }

    // 加载清洗分类为名单
    @RequestMapping("/qingxiActionZhuangList.do")
    @ResponseBody
    public Map<Object, Object> qingxiZhuangtaiList(String status, HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        Map<String, Object> map = new HashMap<>();
        Map<Object, Object> rtnMap = new HashMap<>();
        Integer qingxiStatus = Integer.valueOf(status);
        map.put("qingxiZhuangtai", qingxiStatus);
        try {
            List<ZsQingxi> list = zsqingxiService.findAllZsQingxiNoPage(map);
            rtnMap.put("qingxiList", list);
            rtnMap.put("status", "true");
            rtnMap.put("msg", "查询成功");
        } catch (Exception e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "查询失败");
            e.printStackTrace();
        }
        return rtnMap;
    }

    // 查询待审核的表
    @RequestMapping("/qingxiShenheList.do")
    public ModelAndView qingxiShenheList(HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        Integer pageNo = request.getParameter("pageIndex") == null ? 1 : Integer.valueOf(request
                .getParameter("pageIndex"));
        Map<String, Object> map = new HashMap<String, Object>();
        Integer qingxiHege = 0;
        Integer qingxiZhuangtai = 2;
        map.put("qingxiHege", qingxiHege);
        map.put("qingxiZhuangtai", qingxiZhuangtai);
        map.put("pageNo", pageNo);
        map.put("pageSize", Const.PAGE_SIZE);
        PageInfo<ZsQingxi> page = zsqingxiService.findAllZsQingxi(map);
        request.setAttribute("qingxiList", page.getList());
        request.setAttribute("total", page.getPages());
        request.setAttribute("emMap", StartUpOnLoadData.emMap);
        request.setAttribute("equipMap", StartUpOnLoadData.equipMap);
        request.setAttribute("softMap", StartUpOnLoadData.softMap);
        return new ModelAndView("/qxxd/qingxi_shenhe");
    }

    @RequestMapping("/qingxishenheBaocun.do")
    @ResponseBody
    public Map<Object, Object> qingxiShenhe(String pdata,Integer [] qingxiHege, String[] qingxiLiushui, String qingxiShenherenTiaoma) throws BusinessException {
        Map<Object, Object> rtnMap = new HashMap<>();
        List<ZsPackageImformation> packageImformations = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        if(pdata!=null&&!"".equals(pdata)){
            JSONObject jsonObject = JSONObject.parseObject(pdata);
            JSONArray jsonArray = jsonObject.getJSONArray("datas");
            qingxiShenherenTiaoma = jsonObject.getString("peoplecode");
            qingxiLiushui = new String [jsonArray.size()];
            qingxiHege = new Integer [jsonArray.size()];
            for (int i = 0; i < jsonArray.size(); i++) {
                qingxiLiushui[i] =  JSONObject.parseObject(jsonArray.get(i).toString()).getString("qingxiLiushui");
                qingxiHege[i] = Integer.valueOf(JSONObject.parseObject(jsonArray.get(i).toString()).getString("qingxiHege"));
            }
        }
        map.put("qingxiLiushuiArr", qingxiLiushui);
        List<ZsQingxiMingxi> zsQingxiMingxiList =  zsQingxiMingxiService.findAllQingxiMingxi(map);
        List<String> tiaomaList = new ArrayList<>();
        for(ZsQingxiMingxi zsQingxiMingxi:zsQingxiMingxiList){
            String wlTiaoma = zsQingxiMingxi.getQingxiWanglanTiaoma();
            if(!tiaomaList.contains(wlTiaoma)){
                tiaomaList.add(wlTiaoma);
            }
        }
        String [] qingxiWanglanTiaoma = new String[tiaomaList.size()];
        qingxiWanglanTiaoma = tiaomaList.toArray(qingxiWanglanTiaoma);
        List<ZsPackageImformation> zsPackageImList = zsPackageImService.findAll(map);
        TbEmployee tbEmployee = tbEmployeeService.selectByEmployeeNo(qingxiShenherenTiaoma);
        if (tbEmployee != null) {
            try {
                Date date = new Date();
                Integer hege;
                List<ZsQingxi> list = new ArrayList<>();
                List<ZsQingxiBuhege> buHegelist = new ArrayList<>();
                int count = 0;
                for (int i = 0; i < qingxiHege.length; i++) {
                    hege = Integer.valueOf(qingxiHege[i]);
                    if (hege == 2) {
                        count++;
                    }
                }
                Long[] qingxiBuhegeArr = seqService.seqValBatch("qingxibhgno", count);
                int countBuhege = 0;
                for (int i = 0; i < qingxiHege.length; i++) {
                    hege = Integer.valueOf(qingxiHege[i]);
                    ZsQingxi zsQingxi = zsqingxiService.selectByPrimaryKey(qingxiLiushui[i]);
                    ZsQingxiBuhege zsQingxiBuhege = null;
                    if (hege == 1) {
                        zsQingxi.setQingxiHege(hege);
                        zsQingxi.setQingxiLiushui(qingxiLiushui[i]);
                        zsQingxi.setQingxiShenherenTiaoma(qingxiShenherenTiaoma);
                        zsQingxi.setQingxiJieshuTime(date);
                        zsQingxi.setQingxiShenherenTime(date);
                    } else if (hege == 2) {
                        zsQingxiBuhege = new ZsQingxiBuhege();
                        zsQingxiBuhege.setQingxiLiushui(qingxiLiushui[i]);
                        zsQingxiBuhege.setQingxiShenherenTiaoma(qingxiShenherenTiaoma);
                        zsQingxiBuhege.setQingxiShenherenTime(date);
                        zsQingxiBuhege.setQingxiBuhegeLiushui(String.valueOf(qingxiBuhegeArr[countBuhege]));
                        zsQingxiBuhege.setRecordTime(date);
                        zsQingxi.setQingxiHege(hege);
                        zsQingxi.setQingxiLiushui(qingxiLiushui[i]);
                        zsQingxi.setQingxiShenherenTiaoma(qingxiShenherenTiaoma);
                        zsQingxi.setQingxiShenherenTime(date);
                        zsQingxi.setQingxiZhuangtai(0);
                        buHegelist.add(zsQingxiBuhege);
                        countBuhege++;
                    }
                    list.add(zsQingxi);
                }
                if (buHegelist.size() != 0) {
                    zsQXBhgService.insertBatch(buHegelist);
                }
                String packTm = "";
                for (int i = 0; i < zsPackageImList.size(); i++) {
                    packTm = zsPackageImList.get(i).getPackageTiaoma();
                    String qxLs = zsPackageImList.get(i).getQingxiLiushui();
                    int num = returnNum(qxLs, qingxiLiushui);
                    if (num != -1) {
                        zsPackageImList.get(i).setQingxiShenherenTiaoma(qingxiShenherenTiaoma);
                        zsPackageImList.get(i).setQingxiShenherenTime(date);
                        Integer zsHege = qingxiHege[num];
                        if ("1".equals(zsHege)) {
                            zsPackageImList.get(i).setQingxiHege(Integer.valueOf(zsHege));
                            zsPackageImList.get(i).setQingxiShenherenTiaoma(qingxiShenherenTiaoma);
                            zsPackageImList.get(i).setQingxiShenherenTime(date);
                            TbPackageMuban tbPackageMuban = zsPackageImList.get(i).getTbPackageMuban();
                            if(tbPackageMuban!=null){
                                Integer out = tbPackageMuban.getPackageOutcategory();
                                if(out!=null&&out==1&&zsPackageImList.get(i).getPackageLiuchengZhuangtai()>4){
                                    zsPackageImList.get(i).setPackageLiuchengZhuangtai(9);
                                }else{
                                    zsPackageImList.get(i).setPackageLiuchengZhuangtai(3);
                                }
                            }

                        } else if ("2".equals(zsHege)) {
                            zsPackageImList.get(i).setQingxiHege(Integer.valueOf(zsHege));
                            zsPackageImList.get(i).setQingxiZhuangtai(0);
                            zsPackageImList.get(i).setQingxiShenherenTiaoma(qingxiShenherenTiaoma);
                            zsPackageImList.get(i).setQingxiShenherenTime(date);
                            TbPackageMuban tbPackageMuban = zsPackageImList.get(i).getTbPackageMuban();
                            if(tbPackageMuban!=null){
                                Integer out = tbPackageMuban.getPackageOutcategory();
                                if(out!=null&&out==1&&zsPackageImList.get(i).getPackageLiuchengZhuangtai()>4){
                                    zsPackageImList.get(i).setPackageLiuchengZhuangtai(9);
                                }else{
                                    zsPackageImList.get(i).setPackageLiuchengZhuangtai(3);
                                }
                            }
                        }

                    }

                    if (packTm.startsWith("C")) {
                        // zsPackageImList.get(i).setPackageLiuchengZhuangtai(9);
                    }
                }
                if (zsPackageImList.size() != 0) {
                    zsPackageImService.updateByBatch(zsPackageImList);

                }
                if (list.size() != 0) {
                    zsqingxiService.updataBatch(list);
                }
                updateWlStatus(qingxiWanglanTiaoma, 0);
                updateWlPackStatus(qingxiLiushui, 1);
                rtnMap.put("status", "true");
                rtnMap.put("msg", "审核成功");
            } catch (Exception e) {
                rtnMap.put("status", "false");
                rtnMap.put("msg", "审核失败");
                e.printStackTrace();
            }
        } else {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "无效清洗审核人");
        }

        return rtnMap;
    }

    /**
     * 在一个数组中寻找一个数字的位置
     *
     * @param num
     * @param numArr
     * @return
     */
    public int returnNum(String num, String[] numArr) {
        for (int i = 0; i < numArr.length; i++) {
            if (num.equals(numArr[i])) {
                return i;
            }
        }
        return -1;
    }

    // 清洗明细
    @RequestMapping("/qingxiMingxiList.do")
    @ResponseBody
    public Map<Object, Object> qingxiMingxiList(String id, HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        Map<Object, Object> rtnMap = new HashMap<Object, Object>();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("qingxiLiushui", id);
        try {
            List<ZsWanglanpackage> zsWanglanpacklist = zsWlPackService.findAllWlpackListNoPage(map);
            rtnMap.put("zsWanglanpacklist", zsWanglanpacklist);
            rtnMap.put("status", "true");
            rtnMap.put("msg", "查询成功");
        } catch (Exception e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "查询失败");
            e.printStackTrace();
        }
        return rtnMap;
    }

    // 设置清洗时间
    @RequestMapping("/qingxiTime.do")
    @ResponseBody
    public Map<Object, Object> qingxiTime(String status, String[] qingxiLiushui, HttpServletRequest request,
                                          HttpServletResponse response) throws BusinessException {
        Map<Object, Object> rtnMap = new HashMap<>();
        try {
            Date date = new Date();
            List<ZsQingxi> list = new ArrayList<>();

            // 0开始 1 结束
            if ("0".equals(status)) {
                ZsQingxi zsQingxi = null;
                for (int i = 0; i < qingxiLiushui.length; i++) {
                    zsQingxi = new ZsQingxi();
                    zsQingxi.setQingxiKaishiTime(date);
                    zsQingxi.setQingxiLiushui(qingxiLiushui[i]);
                    zsQingxi.setQingxiZhuangtai(1);
                    zsQingxi.setQingxiHege(0);
                    list.add(zsQingxi);
                }

                Map<String, Object> map = new HashMap<>();
                map.put("qingxiLiushuiArr", qingxiLiushui);
                List<ZsPackageImformation> zsPackageImList = zsPackageImService.findAll(map);

                for (int i = 0; i < zsPackageImList.size(); i++) {

                    zsPackageImList.get(i).setQingxiKaishiTime(date);

                    zsPackageImList.get(i).setQingxiZhuangtai(1);

                }
                if(zsPackageImList.size()!=0){
                    zsPackageImService.updateByBatch(zsPackageImList);
                }


            } else if ("1".equals(status)) {
                ZsQingxi zsQingxi = new ZsQingxi();
                for (int i = 0; i < qingxiLiushui.length; i++) {
                    zsQingxi = new ZsQingxi();
                    zsQingxi.setQingxiJieshuTime(date);
                    zsQingxi.setQingxiLiushui(qingxiLiushui[i]);
                    zsQingxi.setQingxiZhuangtai(2);
                    list.add(zsQingxi);
                }

                Map<String, Object> map = new HashMap<String, Object>();
                map.put("qingxiLiushuiArr", qingxiLiushui);
                List<ZsPackageImformation> zsPackageImList = zsPackageImService.findAll(map);

                for (int i = 0; i < zsPackageImList.size(); i++) {

                    zsPackageImList.get(i).setQingxiJieshuTime(date);

                    zsPackageImList.get(i).setQingxiZhuangtai(2);

                }
                if(zsPackageImList.size()!=0){
                    zsPackageImService.updateByBatch(zsPackageImList);
                }

            }
            zsqingxiService.updataBatch(list);
            rtnMap.put("status", "true");
            rtnMap.put("msg", "成功");

        } catch (Exception e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "查询失败");
            e.printStackTrace();
        }
        return rtnMap;
    }

    // 结束方法
    @RequestMapping("/qingxiEquipTime.do")
    @ResponseBody
    public Map<Object, Object> qingxiEndTime(String status, String equipId, String liushui, HttpServletRequest request,
                                             HttpServletResponse response) throws BusinessException {
        Map<Object, Object> rtnMap = new HashMap<>();
        Map<String, Object> map = new HashMap<>();
        map.put("qingxiLiushui", liushui);
        List<ZsWanglanpackage> wanglanpackages = zsWlPackService.findAllWlpackListNoPage(map);
        try {
            Date date = new Date();
            List<ZsQingxi> list = new ArrayList<ZsQingxi>();
            ZsQingxi zsQingxi = null;
            if (status.equals("1")) {
                zsQingxi = new ZsQingxi();
                zsQingxi.setQingxiKaishiTime(date);
                zsQingxi.setQingxiLiushui(liushui);
                zsQingxi.setQingxiZhuangtai(Integer.valueOf(status));
            } else if (status.equals("2")) {
                zsQingxi = new ZsQingxi();
                zsQingxi.setQingxiJieshuTime(date);
                zsQingxi.setQingxiLiushui(liushui);
                zsQingxi.setQingxiZhuangtai(Integer.valueOf(status));
            }
            list.add(zsQingxi);
            zsqingxiService.updataBatch(list);
            updatePackIm(zsQingxi, wanglanpackages);
            rtnMap.put("status", "true");
            rtnMap.put("msg", "成功");
        } catch (Exception e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "查询失败");
            e.printStackTrace();
        }
        return rtnMap;
    }

    /**
     * 进入添加回收查询界面加载设备信息
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/qingxiInput.do")
    public ModelAndView equipList(HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        Map<String, Object> map = new HashMap<>();
        map.put("wlState", 1);
//        map.put("wlCategory", 1);
        map.put("equipType", 1);
        List<ZsEquip> equipList = zsEquipservice.findAllZsEquipListNoPage(map);
        // 查询出所有没有清洗的回收批次，将批次号码 和网篮取出来
        List<ZsWanglan> wanglan = zsWanglanService.findWanglanListByNoPage(map);
        // 创建对象存储数据
        request.setAttribute("equipList", equipList);
        request.setAttribute("wanglanList", wanglan);
        return new ModelAndView("/qxxd/qingxi_input");
    }

    @RequestMapping("/wanglanList")
    @ResponseBody
    public Map<String, Object> wanglanList() {
        Map<String, Object> map = new HashMap<>();
        map.put("wlState", 1);
        map.put("wlCategory", 1);
        List<ZsWanglan> wanglanList = new ArrayList<>();
        wanglanList = zsWanglanService.findWanglanListByNoPage(map);
        Map<String, Object> rtnMap = new HashMap<>();
        rtnMap.put("datas", wanglanList);
        return rtnMap;
    }

    /**
     * 进入添加清洗设备界面加载设备信息
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/qingxiEquipList.do")
    public ModelAndView qingxiequipList(HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        Map<String, Object> map = new HashMap<>();
        map.put("wlState", 1);
        map.put("wlCategory", 1);
        map.put("equipType", 1);
        List<ZsEquip> equipList = zsEquipservice.findAllZsEquipListNoPage(map);
        // 创建对象存储数据
        request.setAttribute("equipList", equipList);
        return new ModelAndView("/qxxd/qingxi_equipslist");

    }

    /**
     * 通过设备的Id查询设备上的软件信息
     *
     * @param id       设备id
     * @param request
     * @param response
     */
    @RequestMapping("/softMingxiList.do")
    @ResponseBody
    public Map<Object, Object> softList(String id, HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("equipId", id);
        Map<Object, Object> rstmap = new HashMap<Object, Object>();

        try {
            List<ZsSoft> list = zsSoftService.queryZsSoftList(map);
            rstmap.put("softList", list);
            rstmap.put("status", "true");
            rstmap.put("msg", "查询成功");
        } catch (Exception e) {

            rstmap.put("status", "false");
            rstmap.put("msg", "查询失败");
            e.printStackTrace();
        }
        return rstmap;
    }

    // 寻找网篮清单
    @RequestMapping("/findwanglanList.do")
    public ModelAndView findwanglanList(String wltm, HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("wanglanTiaoma", wltm);
        map.put("packageZhuangtai", 0);
        List<ZsWanglanpackage> zsWlpackList = zsWlPackService.findAllWlpackListNoPage(map);
        request.setAttribute("zsWlpackList", zsWlpackList);
        return new ModelAndView("/qxxd/qingxi_wlmxlist");

    }

    // 寻找网篮清单
    @RequestMapping("/findwanglanList")
    @ResponseBody
    public Map<String,Object> findwanglan(String pdata)
            throws BusinessException {
        Map<String, Object> map = new HashMap<>();
        Map<String,Object> rtnMap = new HashMap<>();
        JSONObject jsonObject = JSONObject.parseObject(pdata);
        String wltm = jsonObject.getString("wltm");
        map.put("wanglanTiaoma", wltm);
        map.put("packageZhuangtai", 0);
        List<ZsWanglanpackage> zsWlpackList = zsWlPackService.findAllWlpackListNoPage(map);
        rtnMap.put("datas",zsWlpackList);
        return rtnMap;
    }

    // 新增清洗保存
    @RequestMapping(value = "/save.do")
    @ResponseBody
    public Map<Object, Object> save(String pdata, String ruanjian, String qingxiren, String[] qingxiWanglanTiaoma, HttpServletRequest request,
                                    HttpServletResponse response) throws BusinessException {
        if (StringUtils.isNotBlank(pdata)) {
            JSONObject json = JSONObject.parseObject(pdata);
            ruanjian = json.getString("softCode");
            qingxiren = json.getString("peoplecode");
            JSONArray basketBarcodeArr = json.getJSONArray("datas");
            qingxiWanglanTiaoma = new String[basketBarcodeArr.size()];
            for (int i = 0; i < basketBarcodeArr.size(); i++) {
                qingxiWanglanTiaoma[i] = JSONObject.parseObject(basketBarcodeArr.get(i).toString()).getString("wlTiaoma");
            }
        }
        this.qingxiWanglanTiaoma = qingxiWanglanTiaoma;
        Map<Object, Object> rtnMap = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        ZsQingxi zsQingxi = new ZsQingxi();
        try {
            Integer rjTM = Integer.parseInt(ruanjian);
            ZsSoft zsSoft = zsSoftService.selectByPrimaryKey(rjTM);
            // 判断查询出来的
            TbEmployee tbEmployee = tbEmployeeService.selectByEmployeeNo(qingxiren);
            if (zsSoft != null && zsSoft.getSoftType() == 1) {
                ZsEquip equip = zsSoft.getEquip();
                Integer softId = zsSoft.getSoftId();
                String softName = zsSoft.getSoftName();
                String equipName = equip.getEquipName();
                Integer equipId = equip.getEquipId();
                String proId = "QX" + sdf.format(new Date()) + seqService.seqVal("qingxino");
                zsQingxi.setQingxiLiushui(proId);
                zsQingxi.setQingxiShebeiName(equipName);
                zsQingxi.setQingxiShebeiTiaoma(String.valueOf(equipId));
                zsQingxi.setQingxiRuanjianTiaoma(String.valueOf(softId));
                zsQingxi.setQingxiRuanjianName(softName);
                zsQingxi.setQingxiQingxirenTiaoma(qingxiren.toUpperCase());
                zsQingxi.setQingxiKaishiTime(date);
//                zsQingxi.setQingxiZhuangtai(1);
                zsQingxi.setPackageFlag(1);
                if (tbEmployee != null) {
                    Map<String, Object> map = new HashMap<>();
                    List<String> qxwlTm = new ArrayList<>();

                    qxwlTm = Arrays.asList(qingxiWanglanTiaoma);
                    map.put("wanglanArr", qxwlTm);
                    // //查询大表获得表的条码
                    // List<ZsWanglanpackage> zsWlPacklist =
                    // zsWlPackService.findAllWlpackListNoPage(map);
                    // for(ZsWanglanpackage zspc :zsWlPacklist){
                    // zspc.setPackageZhuangtai(1);
                    // }
                    // 插入清洗表

                    // 这个更新网篮关系表有个重载
                    List<ZsWanglanpackage> zsWlPacklist = updateWlPackStatus(qingxiWanglanTiaoma, zsQingxi);
                    zsQingxi.setPackageNum(zsWlPacklist.size());
                    insertQX(zsQingxi, date, sdf);
                    // 更新大表的状态
                    updatePackIm(zsQingxi, zsWlPacklist);
                    // 更新网篮表
                    updateWlStatus(qingxiWanglanTiaoma, 2);
                    // 插入清洗明细表
                    insertQXMX(qingxiWanglanTiaoma, date, sdf, zsQingxi);

                    rtnMap.put("status", "true");
                    rtnMap.put("msg", "清洗成功");
                } else {
                    rtnMap.put("status", "false");
                    rtnMap.put("msg", "清洗人条码无效");
                }
            } else {
                rtnMap.put("status", "false");
                rtnMap.put("msg", "软件条码无效或不是清洗程序");
            }
        } catch (NumberFormatException e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "软件条码无效");
            e.printStackTrace();
        } catch (Exception e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "清洗失败");
            e.printStackTrace();
        }
        return rtnMap;
    }

    /**
     * 插入清洗明细表
     *
     * @param qingxiWanglanTiaoma
     * @param dt
     * @param sdf
     * @param qingxi
     */
    private void insertQXMX(String[] qingxiWanglanTiaoma, Date dt, SimpleDateFormat sdf, ZsQingxi qingxi)
            throws BusinessException {
        String qingximingxiId;
        ZsQingxiMingxi zsQingxiMingxi = null;
        int qxmxNum = qingxiWanglanTiaoma.length;
        Long[] qxmxArr = seqService.seqValBatch("qingximingxino", qxmxNum);
        List<ZsQingxiMingxi> zsQingxiList = new ArrayList<>();
        for (int i = 0; i < qingxiWanglanTiaoma.length; i++) {
            zsQingxiMingxi = new ZsQingxiMingxi();
            qingximingxiId = "QXMX" + sdf.format(new Date()) + qxmxArr[i];
            zsQingxiMingxi.setQingxiLiushui(qingxi.getQingxiLiushui());
            zsQingxiMingxi.setQingxiMingxiLiushui(qingximingxiId);
            zsQingxiMingxi.setQingxiHege(0);
            zsQingxiMingxi.setQingxiWanglanTiaoma(qingxiWanglanTiaoma[i]);
            zsQingxiMingxi.setRecordTime(dt);
            zsQingxiMingxi.setQingxiChangStatus(0);
            zsQingxiList.add(zsQingxiMingxi);
        }

        zsQingxiMingxiService.insertBatch(zsQingxiList);
    }

    /**
     * 插入清洗表
     *
     * @param zsQingxi
     * @param dt
     * @param sdf
     * @return
     */
    private ZsQingxi insertQX(ZsQingxi zsQingxi, Date dt, SimpleDateFormat sdf) throws BusinessException {
        zsQingxi.setRecordTime(dt);
        int status = 2;
        int shenhe = 0;
        zsQingxi.setQingxiZhuangtai(status);
        zsQingxi.setQingxiHege(shenhe);
        return zsqingxiService.insert(zsQingxi);
    }

    /**
     * 更新大表的状态
     *
     * @param zsQingxi
     * @param zsWlPacklist
     */
    private void updatePackIm(ZsQingxi zsQingxi, List<ZsWanglanpackage> zsWlPacklist) throws BusinessException {
        List<ZsPackageImformation> packTmList = new ArrayList<>();
        ZsPackageImformation zsPackageImformation = null;
        String[] packIm = new String[zsWlPacklist.size()];
        int count = 0;
        for (ZsWanglanpackage zsWanglanpackage : zsWlPacklist) {
            zsPackageImformation = new ZsPackageImformation();
            packIm[count] = zsWanglanpackage.getPackageTiaoma();
            if (count > 0) {
                if (packIm[count] == packIm[count - 1]) {
                    count++;
                    continue;
                }
            }
            zsPackageImformation.setQingxiLiushui(zsQingxi.getQingxiLiushui());
            zsPackageImformation.setPackageTiaoma(zsWanglanpackage.getPackageTiaoma());
            zsPackageImformation.setQingxiQingxirenTiaoma(zsQingxi.getQingxiQingxirenTiaoma());
            zsPackageImformation.setQingxiRuanjianTiaoma(zsQingxi.getQingxiRuanjianTiaoma());
            zsPackageImformation.setQingxiShebeiTiaoma(zsQingxi.getQingxiShebeiTiaoma());
            zsPackageImformation.setQingxiKaishiTime(new Date());
            ZsPackageImformation packageImformation = zsPackageImService.selectByPrimaryKey(zsWanglanpackage
                    .getPackageTiaoma());
            TbPackageMuban tbPackageMuban = packageImformation.getTbPackageMuban();
           if(tbPackageMuban!=null){
               Integer out = tbPackageMuban.getPackageOutcategory();
               if(out !=null&&out==1&&packageImformation.getPackageLiuchengZhuangtai()>4){
                   zsPackageImformation.setPackageLiuchengZhuangtai(9);
               }
           }else{
               zsPackageImformation.setPackageLiuchengZhuangtai(2);
           }
            if (zsQingxi.getQingxiZhuangtai() == 2) {
                //好坑的代码
                zsPackageImformation.setQingxiJieshuTime(new Date());
            }
            zsPackageImformation.setQingxiZhuangtai(zsQingxi.getQingxiZhuangtai());
            zsPackageImformation.setQingxiHege(zsQingxi.getQingxiHege());
            if(tbPackageMuban!=null){
                Integer integer = tbPackageMuban.getPackageOutcategory();
                if(integer!=null){
                    if(integer!=1){
                        packTmList.add(zsPackageImformation);
                    }else if(integer !=null&&integer==1&&packageImformation.getPackageLiuchengZhuangtai()<4){
                        packTmList.add(zsPackageImformation);
                    }
                }else{
                    packTmList.add(zsPackageImformation);
                }
            }

            count++;
        }
        if (packTmList.size() != 0) {
            zsPackageImService.updateByBatch(packTmList);
        }

    }

    /**
     * 根据清洗的流水更改包的状态，改为清洗状态 更改为1。多网篮的包如果已经配包则不改
     *
     * @param qingxiLiushui
     * @param status        更改网篮包表包的状态
     * @zsQingxi 更改他们清洗流水
     */
    public void updateWlPackStatus(String[] qingxiLiushui, Integer status) throws BusinessException {
        Map<String, Object> map = new HashMap<>();
        map.put("qingxiLiushuiArr", qingxiLiushui);
        List<ZsWanglanpackage> zsWllist = zsWlPackService.findAllWlpackListNoPage(map);
        for (ZsWanglanpackage zswl : zsWllist) {
            if (status != null) {
                if (zswl.getPackageZhuangtai() != 2) {
                    zswl.setPackageZhuangtai(status);
                }
            }
        }
        if(zsWllist.size()!=0){
            zsWlPackService.updateBatch(zsWllist);
        }

    }

    /**
     * 判断清洗流水为空的清洗记录 改变它们的状态 抛异常要清除数据
     *
     * @param qingxiWanglanTiaoma
     * @param zsQingxi
     * @throws BusinessException
     */
    public List<ZsWanglanpackage> updateWlPackStatus(String[] qingxiWanglanTiaoma, ZsQingxi zsQingxi)
            throws BusinessException {
        Map<String, Object> map = new HashMap<>();
        map.put("wanglanArr", qingxiWanglanTiaoma);
        map.put("insertQXLS", "");

        List<ZsWanglanpackage> zsWllist = zsWlPackService.findAllWlpackListNoPage(map);
        for (ZsWanglanpackage zswl : zsWllist) {
            if (zsQingxi != null) {
                zswl.setQingxiLiushui(zsQingxi.getQingxiLiushui());
            }
        }
        if (zsWllist.size() != 0) {
            zsWlPackService.updateBatch(zsWllist);
        }
        return zsWllist;

    }

    private void updateWlStatus(String[] qingxiWanglanTiaoma, int status) throws BusinessException {
        List<ZsWanglan> zsWllist = new ArrayList<>();
        ZsWanglan zsWanglan = null;
        for (int i = 0; i < qingxiWanglanTiaoma.length; i++) {
            zsWanglan = new ZsWanglan();
            zsWanglan.setWlState(status);
            zsWanglan.setWlTiaoma(qingxiWanglanTiaoma[i]);
            zsWllist.add(zsWanglan);
        }
        if(zsWllist.size()!=0){
            zsWanglanService.updateBatch(zsWllist);
        }

    }

    // 清洗修改
    @RequestMapping("/qingxiEdit.do")
    public ModelAndView packageingEdit(String qingxiLiushui, HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        ZsQingxi zsQingxi = zsqingxiService.selectByPrimaryKey(qingxiLiushui);
        Map<String,Object> map = new HashMap<>();
//        Integer equipCategory = 182;
//        map.put("equipCategory",equipCategory);
        map.put("equipType",1);
        List<ZsEquip> zsEquips = zsEquipService.findAllZsEquipListNoPage(map);
//        List<ZsSoft> zsSofts = zsEquipService.findAllZsEquipListNoPage(map);
        request.setAttribute("zsEquips",zsEquips);
        request.setAttribute("zsQingxi", zsQingxi);
        request.setAttribute("emMap", StartUpOnLoadData.emMap);
        return new ModelAndView("/qxxd/qingxi_edit");
    }

    // 清洗修改
    @RequestMapping("/qingxiEdit")
    @ResponseBody
    public Map<String,Object> packageEdit(String qingxiLiushui, HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        Map<String,Object> rtnMap = new HashMap<>();
        ZsQingxi zsQingxi = zsqingxiService.selectByPrimaryKey(qingxiLiushui);
        if(zsQingxi.getQingxiZhuangtai()==0||zsQingxi.getQingxiZhuangtai()==2){
            rtnMap.put("status",true);
            rtnMap.put("qingxi",zsQingxi);
            rtnMap.put("msg","可以修改");
        }else if(zsQingxi.getQingxiZhuangtai() == 1){
            rtnMap.put("status",false);
            rtnMap.put("qingxi",zsQingxi);
            rtnMap.put("msg","已经开始清洗，不能修改记录");
        }
        return rtnMap;
    }

    // 清洗修改保存
    @RequestMapping("/qingxiEditSave.do")
    @ResponseBody
    public Map<Object, Object> packageingSave(ZsQingxi zsQingxi, HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        Map<Object, Object> rtnMap = new HashMap<>();
        try {
            zsQingxi.setRecordTime(new Date());
            int i = zsqingxiService.updateByPrimaryKey(zsQingxi);
            if (i == 1) {
                rtnMap.put("status", "true");
                rtnMap.put("msg", "编辑成功");
            } else {
                rtnMap.put("status", "false");
                rtnMap.put("msg", "编辑失败");
            }
        } catch (Exception e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "编辑失败");
            e.printStackTrace();
        }
        return rtnMap;
    }

    @RequestMapping("/qingxiDel.do")
    @ResponseBody
    public Map<Object, Object> packageingDel(HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        Map<Object, Object> rtnMap = new HashMap<Object, Object>();
        try {
            String ids = request.getParameter("id");
            String[] arraId = ids.split(",");
            for (String tid : arraId) {
                zsqingxiService.deleteByPrimaryKey(tid);
                zsQingxiMingxiService.deleteByQingxiLiushui(tid);
            }
            rtnMap.put("status", "true");
            rtnMap.put("msg", "删除成功");
        } catch (Exception e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "删除失败");
            e.printStackTrace();
        }
        return rtnMap;
    }

    // /**点击回收批次查询明细内容 */
    // @RequestMapping("/qingxiMingxiList.do")
    // public void qingxiMingxiList(String id,HttpServletRequest
    // request,HttpServletResponse response){
    // Map<Object, Object> rtnMap = new HashMap<Object,Object>();
    // try {
    // Map<String,Object> map =new HashMap<String,Object>();
    // if(StringUtils.isNotBlank(id)){
    // map.put("qingxiLiushui", id);
    // }
    // // List<ZsQingxiMingxi> mingxiList =
    // zsHuishouMingxi.findAllHuishouMingxi(map);
    // rtnMap.put("mxList", mingxiList);
    // rtnMap.put("status", "true");
    // rtnMap.put("msg", "编辑成功");
    // } catch (Exception e) {
    // rtnMap.put("status", "false");
    // rtnMap.put("msg", "编辑失败");
    // e.printStackTrace();
    // }
    // writeByMapString(rtnMap);
    //
    // }

    @RequestMapping("/qingxiMachiesList.do")
    public ModelAndView qingxiMachiesList(HttpServletRequest request, HttpServletResponse response)
            throws BusinessException {
        // List<ZsEquip> equips = zsEquipservice.findAllZsEquipListNoPage(new
        // HashMap<String,Object>());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> map1 = new HashMap<>();
        map1.put("qingxiZhuangtai", 0);
        List<ZsQingxi> qingxis = zsqingxiService.findAllZsQingxiNoPage(map1);
        Map<String, String[]> equipIdqxls = new HashMap<>();
        List<ZsEquip> list = new ArrayList<>();
        Integer qingxiStatus = 0;
        map.put("qingxiZhuangtai", qingxiStatus);
        // List<ZsQingxi> zsQingxiList =
        // zsqingxiService.findAllZsQingxiNoPage(map);
        map.put("wlState", 1);
        map.put("wlCategory", 1);
        map.put("equipType", 1);
        List<ZsEquip> equipList = zsEquipservice.findAllZsEquipListNoPage(map);
        // 创建对象存储数据
        List<String> shebeiTiaomas = new ArrayList<>();
        String[] qxxdLiushuiSoftId = null;
        ZsQingxi qingxi = null;
        for (ZsEquip zsEquip : equipList) {
            map.put("qingxiShebeiTiaoma", zsEquip.getEquipId());
            map.put("qingxiZhuangtai", 1);
            qingxi = zsqingxiService.findOne(map);
            if (qingxi != null) {
                if (!shebeiTiaomas.contains(qingxi.getQingxiShebeiTiaoma())) {
                    qxxdLiushuiSoftId = new String[3];
                    shebeiTiaomas.add(qingxi.getQingxiShebeiTiaoma());
                    qxxdLiushuiSoftId[0] = qingxi.getQingxiLiushui();
                    qxxdLiushuiSoftId[1] = qingxi.getQingxiRuanjianTiaoma();
                    qxxdLiushuiSoftId[2] = sdf.format(qingxi.getQingxiKaishiTime());
                    equipIdqxls.put(qingxi.getQingxiShebeiTiaoma(), qxxdLiushuiSoftId);
                }
            }
            list.add(zsEquip);
        }
        if (!list.isEmpty()) {
            request.setAttribute("equipList", list);
        }
        if (!qingxis.isEmpty()) {
            request.setAttribute("qingxiList", qingxis);
        }
        // Map<String, Object> oneMap = new HashMap<String, Object>();
        // oneMap.put("status", 1);
        request.setAttribute("qingxiIng", JSON.toJSON(shebeiTiaomas));
        request.setAttribute("equipIdQxls", JSON.toJSON(equipIdqxls));
        request.setAttribute("softAll", JSON.toJSON(StartUpOnLoadData.softMap));
        request.setAttribute("empMap", StartUpOnLoadData.emMap);
        /*
         * request.setAttribute("equipList", equipList);
         * request.setAttribute("zsQingxiList", zsQingxiList);
         */
        request.setAttribute("empMap", StartUpOnLoadData.emMap);
        return new ModelAndView("/qxxd/qingxi_equipslist");
    }

    // 新增清洗保存
    @RequestMapping(value = "/cleanoutAndroid")
    @ResponseBody
    public Map<Object, Object> cleanoutAndroid(String pdata, HttpServletRequest request,
                                               HttpServletResponse response) throws BusinessException {
        Map<Object, Object> rtnMap = new HashMap<>();
        JSONObject json = JSONObject.parseObject(pdata);
        String ruanjian = json.getString("softCode");
        String qingxiren = json.getString("peoplecode");
        JSONArray basketBarcodeArr = json.getJSONArray("datas");
        String[] qingxiWanglanTiaoma = new String[basketBarcodeArr.size()];

        for (int i = 0; i < basketBarcodeArr.size(); i++) {
            qingxiWanglanTiaoma[i] = JSONObject.parseObject(basketBarcodeArr.get(i).toString()).getString("wlTiaoma");
        }


        Date date = new Date();
        ZsQingxi zsQingxi = new ZsQingxi();

        try {
            Integer rjTM = Integer.parseInt(ruanjian);
            ZsSoft zsSoft = zsSoftService.selectByPrimaryKey(rjTM);
            // 判断查询出来的
            TbEmployee tbEmployee = tbEmployeeService.selectByEmployeeNo(qingxiren);
            for (int i = 0; i < qingxiWanglanTiaoma.length; i++) {
                ZsWanglan zsWanglan = zsWanglanService.selectByPrimaryKey(qingxiWanglanTiaoma[i]);
                if (zsWanglan.getWlState() != 1) {
                    rtnMap.put("status", "false");
                    rtnMap.put("msg", "网篮条码无效");
                    return rtnMap;
                }

            }
            if (zsSoft != null) {
                ZsEquip equip = zsSoft.getEquip();
                Integer softId = zsSoft.getSoftId();
                String softName = zsSoft.getSoftName();
                String equipName = equip.getEquipName();
                Integer equipId = equip.getEquipId();
                zsQingxi.setQingxiShebeiName(equipName);
                zsQingxi.setQingxiShebeiTiaoma(String.valueOf(equipId));
                zsQingxi.setQingxiRuanjianTiaoma(String.valueOf(softId));
                zsQingxi.setQingxiRuanjianName(softName);
                zsQingxi.setQingxiQingxirenTiaoma(qingxiren);
                zsQingxi.setQingxiKaishiTime(date);
                if (tbEmployee != null && tbEmployee.getEmployeeNo().equals(qingxiren)) {
                    Map<String, Object> map = new HashMap<String, Object>();
                    List<String> qxwlTm = new ArrayList<String>();
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                    qxwlTm = Arrays.asList(qingxiWanglanTiaoma);
                    map.put("wanglanArr", qxwlTm);
                    // //查询大表获得表的条码
                    // List<ZsWanglanpackage> zsWlPacklist =
                    // zsWlPackService.findAllWlpackListNoPage(map);
                    // for(ZsWanglanpackage zspc :zsWlPacklist){
                    // zspc.setPackageZhuangtai(1);
                    // }
                    // 插入清洗表
                    ZsQingxi qingxi = insertQX(zsQingxi, date, sdf);
                    // 这个更新网篮关系表有个重载
                    List<ZsWanglanpackage> zsWlPacklist = updateWlPackStatus(qingxiWanglanTiaoma, qingxi);
                    // 更新大表的状态
                    updatePackIm(zsQingxi, zsWlPacklist);
                    // 更新网篮表
                    updateWlStatus(qingxiWanglanTiaoma, 2);
                    // 插入清洗明细表
                    insertQXMX(qingxiWanglanTiaoma, date, sdf, qingxi);

                    rtnMap.put("status", "true");
                    rtnMap.put("msg", "清洗成功");
                } else {
                    rtnMap.put("status", "false");
                    rtnMap.put("msg", "清洗人条码无效");
                }
            } else {
                rtnMap.put("status", "false");
                rtnMap.put("msg", "软件条码无效");
            }
        } catch (NumberFormatException e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "软件条码无效");
            e.printStackTrace();
        } catch (Exception e) {
            rtnMap.put("status", "false");
            rtnMap.put("msg", "清洗失败");
            e.printStackTrace();
        }
        return rtnMap;
    }


}
